<?php 
include_once('includes.php'); 

$where=" where  status=2  ";
//paging--------------
include_once('../includes/paging.class.php');

$q_str = $_SERVER['QUERY_STRING'];
if(isset($_GET['page']))
{
  $q_str = str_replace('page='.$_GET['page'],'',$_SERVER['QUERY_STRING']);    
}
$sql = "select count(*) as total from highlights left join matchs on highlights.match_id = matchs.id left join competition on matchs.competition_id = competition.id $where ";
$r=db_fetch_one($sql);
$total=$r->total;

$paging = new Paging();

$paging->assign ( 'highlights?'.$q_str ,  $total , 20 );
$limit = ' Limit '.$paging->sql_limit();

//-------------------
	
$sql = "select  highlights.id as hid, highlights.* ,matchs.*, competition.name as cname, competition.classicon as cicon from   highlights left join matchs on highlights.match_id = matchs.id left join competition on matchs.competition_id = competition.id $where order by kick_off desc $limit";
$highlights=db_fetch_all($sql);

?>
<?php include_once('includes/header.php'); 	 ?>
<span class="title">Highlights </span>

<table> 
	<thead>
		<tr>
			<th> Competition </th>
			<th> Result</th>
			<th> Kick off </th>
			
			<th> </th>
		</tr>
	</thead>
	
<?php 
foreach($highlights as $highlight)
{
	$local_kick_off = convertTimeToLocal($highlight->kick_off,$highlight->timezone);
	
	list($team1, $team2 ) = split('-',$highlight->versus);
	$team1 = trim($team1);
	$team2 = trim($team2);

?>
	<tr>
		<td class="<?php echo $highlight->cicon; ?>"><?php echo $highlight->cname;?></td>
		<td <?php echo ($highlight->is_feature)?"class='feature-match'":"";?>><?php echo $team1." ".$highlight->score." ".$team2;?></td>
		<td><?php echo formatOutputDate($local_kick_off);?></td>
		<td><a href="create-highlight?match_id=<?php echo $highlight->id; ?>">Edit</a> | <a onclick="if(!confirm('Do you want to delete this highlight?')) return false;" href="create-highlight?task=delete&match_id=<?php echo $highlight->id; ?>">Delete</a></td>
	</tr>
<?php
}
?>
</table>

<div class="pager">
<?php
	echo $paging->fetch();
?>
</div>
<?php include_once('includes/footer.php'); 	 ?>